<?php
declare (strict_types=1);

namespace app\api\controller;

use think\facade\View;
use think\response\Json;
use app\common\model\Remit as RemitModel;
use think\exception\ValidateException;

class Remit extends Base
{

    public function index(): Json
    {
        $result['remit_make'] = [
            [
                'type' => '微信',
                'image' => handleImg($this->system['remit_wechat'])
            ],
            [
                'type' => '支付宝',
                'image' => handleImg($this->system['remit_alipay'])
            ],
            [
                'type' => '银行卡',
                'bank_name' => $this->system['remit_bank_name'],
                'bank_open' => $this->system['remit_bank_open'],
                'bank_account' => $this->system['remit_bank_account'],
                'bank_number' => $this->system['remit_bank_number'],
            ],
        ];
        $result['remit_factor'] = [
            'remit_open' => $this->system['remit_open'],
            'remit_min' => $this->system['remit_min'],
            'remit_bs' => $this->system['remit_bs'],
            'remit_msg' => $this->system['remit_msg'],
        ];
        return json(['code' => 1, 'msg' => 'success', 'result' => $result]);
    }

    public function getList(): Json
    {
        $param = $this->request->param();

        $map = ['uid' => $this->user->id, 'is_del' => 0];

        return json(RemitModel::getPageList($map, 'id,account,amount,create_time,status,reject_msg,pay_way', $param['page'], 20, false));
    }

    public function save(): Json
    {
        $param = $this->request->post('', '', $this->filter);
        try {
            $this->validate($param, 'Remit');
        } catch (ValidateException $e) {
            return json(['code' => -1, 'msg' => $e->getError()]);
        }
        return json(RemitModel::add($param, $this->user, $this->system));
    }

}

